package com.angus.common.core.enums;

import lombok.Getter;

@Getter
public enum DeviceType {
    UNKNOWN(0,"unknown","未知"),
    PHONE(1,"phone","手机号"),
    EMAIL(2,"email","邮箱");

    private final Integer typeFlag;
    private final String typeCode;
    private final String typeName;

    DeviceType(Integer typeFlag, String typeCode, String typeName) {
        this.typeFlag = typeFlag;
        this.typeCode = typeCode;
        this.typeName = typeName;
    }

    public static String fromFlag(Integer typeFlag) {
        DeviceType[] values = DeviceType.values();
        for (DeviceType value : values) {
            if (value.getTypeFlag().equals(typeFlag)) {
                return value.getTypeCode();
            }
        }
        return "UNKNOWN";
    }

    public static Integer fromCode(String typeCode) {
        DeviceType[] values = DeviceType.values();
        for (DeviceType value : values) {
            if (value.getTypeCode().equals(typeCode)) {
                return value.getTypeFlag();
            }
        }
        return UNKNOWN.getTypeFlag();
    }
}
